home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form LockForm
- AutoRedraw = -1 'True
- BorderStyle = 1 'Fixed Single
- Caption = "SWBLogicalLocks Sample Application"
- ClientHeight = 4590
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 6675
- ControlBox = 0 'False
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 4590
- ScaleWidth = 6675
- StartUpPosition = 2 'CenterScreen
- Begin VB.Frame Frame2
- Caption = "Logical Locks Held By This Station"
- Height = 3075
- Left = 135
- TabIndex = 8
- Top = 1395
- Width = 6405
- Begin VB.ListBox LockList
- Height = 1815
- Left = 135
- TabIndex = 10
- Top = 675
- Width = 6090
- End
- Begin VB.CommandButton RefreshBtn
- Caption = "R&efresh"
- Height = 330
- Left = 3825
- TabIndex = 4
- Top = 2625
- Width = 1125
- End
- Begin VB.CommandButton UnlockBtn
- Caption = "&Release"
- Height = 330
- Left = 5130
- TabIndex = 5
- Top = 2625
- Width = 1125
- End
- Begin VB.Label Label2
- BorderStyle = 1 'Fixed Single
- Caption = " Handle Name Owner Type"
- Height = 285
- Left = 135
- TabIndex = 11
- Top = 360
- Width = 6090
- End
- End
- Begin VB.CommandButton CloseBtn
- Cancel = -1 'True
- Caption = "&Close"
- Height = 375
- Left = 5310
- TabIndex = 6
- Top = 225
- Width = 1215
- End
- Begin VB.Frame Frame1
- Caption = "Acquire Lock"
- Height = 1095
- Left = 135
- TabIndex = 7
- Top = 135
- Width = 5010
- Begin VB.CommandButton LockBtn
- Caption = "&Acquire"
- Default = -1 'True
- Height = 330
- Left = 3700
- TabIndex = 3
- Top = 675
- Width = 1125
- End
- Begin VB.TextBox LockName
- Height = 315
- Left = 675
- MaxLength = 64
- TabIndex = 0
- Top = 315
- Width = 4155
- End
- Begin VB.OptionButton LockType
- Caption = "Shareable"
- Height = 195
- Index = 1
- Left = 1890
- TabIndex = 2
- Top = 765
- Width = 1230
- End
- Begin VB.OptionButton LockType
- Caption = "Exclusive"
- Height = 195
- Index = 0
- Left = 675
- TabIndex = 1
- Top = 765
- Value = -1 'True
- Width = 1230
- End
- Begin VB.Label Label1
- AutoSize = -1 'True
- Caption = "Name"
- Height = 195
- Left = 135
- TabIndex = 9
- Top = 360
- Width = 420
- End
- End
- Attribute VB_Name = "LockForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '============================================================
- ' SWBLogicalLocks Sample Application.
- ' This program contains the code necessary
- ' to create and release logical locks.
- '============================================================
- Option Explicit
- 'Declare a reference to the Logical Locks object.
- Private LogLock As LogicalLock
- 'Descriptions for "Exclusive" and "Shareable" locks.
- Private LockTypeDesc(1) As String
- Private Sub LockBtn_click()
- Dim Handle As Long
- 'Lock Name should not be blank.
- If (Trim(LockName.Text) = "") Then
- MsgBox "You must specify a Lock Name", vbExclamation, "Missing Lock Name"
- Exit Sub
- End If
- 'Acquire the lock (if possible) and return a handle to it.
- Handle = LogLock.AcquireLock(Trim(LockName.Text), IIf(LockType(0).Value = True, Exclusive, Shareable))
- If Handle <> 0 Then
- MsgBox "Lock Successfully Acquired", vbInformation, "Lock Acquired"
- Else 'If Handle is zero, then lock was not acquired.
- MsgBox "Lock could not be acquired", vbExclamation, "Lock Unsuccessful"
- End If
- UpdateLockList
- End Sub
- Private Sub RefreshBtn_Click()
- 'Update the list of locks held by this station.
- UpdateLockList
- End Sub
- Private Sub UnlockBtn_Click()
- Dim Res As Boolean
- Dim Hdl As Long
- If (LockList.ListCount = 0) Then
- MsgBox "You are not currently holding any locks.", vbInformation, "No Locks"
- Exit Sub
- End If
- If (LockList.ListIndex = -1) Then
- MsgBox "You must select a lock to release.", vbInformation, "No Lock Selected"
- Exit Sub
- End If
- Hdl = LockList.ItemData(LockList.ListIndex)
- 'Release the lock specified by the handle (Hdl).
- Res = LogLock.ReleaseLock(Hdl)
- 'If ReleaseLock returns True, then lock was successfully released.
- If (Res = True) Then
- MsgBox "Lock Released", vbInformation, "Lock Released"
- Else
- MsgBox "Lock was not released.", vbExclamation, "Lock Not Released"
- End If
- UpdateLockList
- End Sub
- Private Sub UpdateLockList()
- Dim LockName As String
- Dim LockUser As String
- Dim LockType As Integer
- Dim LockHndl As Long
- Dim User As String
- Dim Res As Boolean
- 'Enumerate the locks held by this station.
- 'Add them to a list box showing all the
- 'properties of a logical lock:
- 'Name, Owner, Type, and Handle.
- Screen.MousePointer = vbHourglass
- User = LogLock.UserName
- LockHndl = 0&
- Res = LogLock.EnumerateLocks(LockHndl, User)
- LockList.Clear
- 'EnumerateLocks returns True as long as another lock
- 'was found for the specified user.
- Do While (Res = True)
- If (LogLock.GetLockInfo(LockHndl, LockName, LockUser, LockType) = True) Then
- LockList.AddItem Format(LockHndl) & vbTab & LockName & vbTab & LockUser & vbTab & LockTypeDesc(LockType)
- LockList.ItemData(LockList.NewIndex) = LockHndl
- End If
-
- Res = LogLock.EnumerateLocks(LockHndl, User)
- Loop
- If (LockList.ListCount > 0) Then LockList.ListIndex = 0
- Screen.MousePointer = vbDefault
- End Sub
- Private Sub CloseBtn_Click()
- Unload Me
- End Sub
- Private Sub Form_Load()
- Dim Row As Integer
- Dim Stops(3) As Long
- Dim Res As Long
- 'Instantiate a new logical lock object.
- Set LogLock = New LogicalLock
- 'Set the database directory path.
- LogLock.DatabaseDir = App.Path
- 'Now start the logical lock server.
- LogLock.InitializeLocks "loglock.mdb"
- 'Set up columns in the logical lock list box.
- Stops(0) = 40
- Stops(1) = 160
- Stops(2) = 220
- Res = SendMessage(LockList.hwnd, LB_SETTABSTOPS, 3&, Stops(0))
- 'Initialize lock type descriptions.
- LockTypeDesc(0) = "Exclusive"
- LockTypeDesc(1) = "Shareable"
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- 'Before closing the application completely,
- 'shut down the logical lock server and
- 'destroy its reference.
- LogLock.ShutdownLocks
- Set LogLock = Nothing
- End Sub
-